<template>
  <div>
    <el-table :data="tableData" border v-loading="loading" :header-cell-style="{'text-align':'center'}"
              :cell-style="{'text-align':'center'}">
      <el-table-column fixed prop="id" label="编号" width="80"></el-table-column>
      <el-table-column prop="age" label="年龄/月" width="80"></el-table-column>
      <el-table-column prop="sex" label="性别" width="80"></el-table-column>
      <el-table-column prop="cat_sort" label="分类" width="80"></el-table-column>
      <el-table-column prop="height" label="身高" width="100"></el-table-column>
      <el-table-column prop="weight" label="体重" width="100"></el-table-column>
      <el-table-column prop="pic" label="图片路径" width="120"></el-table-column>
      <el-table-column prop="price" label="价格" width="80"></el-table-column>
      <el-table-column prop="is_coupon" label="优惠码" width="80"></el-table-column>
      <el-table-column prop="sale_count" label="销售量" width="80"></el-table-column>
      <el-table-column prop="memo" label="地址" width="150"></el-table-column>
      <el-table-column prop="details" label="描述" width="150"></el-table-column>
      <el-table-column label="操作" width="260">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" @click="edit(scope.row)">修改</el-button>
          <el-popconfirm title="确认删除吗?" @confirm="del(scope.row)">
            <el-button slot="reference" type="warning" icon="el-icon-delete">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next"
                   :total="total" page-size="6" @current-change="page"
                   style="margin:20px;">
    </el-pagination>

  </div>
</template>

<script>
  export default {
    name: "PetManage",
    data() {
      return {
        pageSize: null,
        total: null,
        tableData: null,
        loading: false
      }
    },
    methods: {
      page(currentPage) {
        //alert(currentPage)  输出分页的信息 测试
        const _this = this
        this.$axios.get('http://localhost:9000/cat/findPage/' + currentPage + '/6').then(function (resp) {
          //console.log(resp)
          _this.tableData = resp.data.content
          _this.pageSize = resp.data.size
          _this.total = resp.data.totalElements
        })
      },
      edit(row) {
        this.$router.push({
          path: '/myUpdate/updatePet',
          query: {
            id: row.id
          }
        });
      },
      del(row) {
        const _this = this
        this.$axios.delete('http://localhost:9000/cat/del/' + row.id).then(function (resp) {
          _this.$alert('编号<' + row.id + '>已删除', '消息', {
            confirmButtonText: '确定',
            callback: action => {
              window.location.reload()
            }
          });
        })
      }
    },
    created() {
      const _this = this
      this.$axios.get('http://localhost:9000/cat/findPage/1/6').then(function (resp) {
        //console.log(resp)
        _this.tableData = resp.data.content
        _this.pageSize = resp.data.size
        _this.total = resp.data.totalElements
      })
    }
  }
</script>

<style scoped>

</style>
